<?php
// 用户模型
class CommodityInfoModel extends CommonModel {
	protected $pk     = 'commodity_id';
	
	var $info = array();
	
	function ini(){
		$sql = "select cpii.brief_pic,ci.* from ar_shop.commodity_info as ci
				left join (select * from ar_shop.commodity_pic_info as cpi where cpi.type=1) as cpii on cpii.commodity_id = ci.commodity_id
				where ci.is_cancle=0";
		$db_res = $this->query($sql);
		$db_res = $this->query($sql);
		if(empty($db_res)){$db_res = array();}
		foreach ($db_res as $row){
			$this->info[$row['commodity_id']]['commodity_id'] = $row['commodity_id'];//商品id
			$this->info[$row['commodity_id']]['name'] = $row['name'];//商品名称
			$this->info[$row['commodity_id']]['sale_cycle'] = $row['sale_cycle'];//销售周期
			$this->info[$row['commodity_id']]['spec'] = $row['spec'];//商品规格
			$this->info[$row['commodity_id']]['origin'] = $row['origin'];//产地
			$this->info[$row['commodity_id']]['unit_id'] = $row['unit_id'];//商品单位id
			$this->info[$row['commodity_id']]['market_price'] = $row['market_price'];//显示市场价
			$this->info[$row['commodity_id']]['sale_price'] = $row['sale_price'];//销售价格梯度
			$this->info[$row['commodity_id']]['brief_pic'] = C('HTTP_IMG') .$row['brief_pic'];//商品封面小图
			$this->info[$row['commodity_id']]['is_onsale'] = $row['is_onsale'];
			$this->info[$row['commodity_id']]['supply_begin'] = $row['supply_begin'];//供应起始日
			$this->info[$row['commodity_id']]['supply_end'] = $row['supply_end'];//供应截止日
			$this->info[$row['commodity_id']]['brief_desc'] = $row['brief_desc'];//
			
		}
	}
	
	function commodity_info($id = null)
	{
		if(empty($id)){
			return $this->info;
		}else if(empty($this->info[$id])) {
			return array();
		}else{
			return $this->info[$id];
		}
	}
}
?>